/**
 * sku 相关
 */

import service from '@/utils/request'
import type { skuListResponse, skuInfoModel } from '@/api/product/model/sku'

enum API {
  // 保存 sku
  saveSkuInfo = '/admin/product/saveSkuInfo',

  // 获取 skuList
  getSkuList = '/admin/product/list',

  // 上架
  onSale = '/admin/product/onSale',
  // 下架
  cancelSale = '/admin/product/cancelSale',
  // 删除 
  deleteSkuInfo = '/admin/product/deleteSku',

  // 获取 spu 中的 sku
  getSkuListBySpuId = '/admin/product/findBySpuId',

  // 获取 sku 的详细信息
  getSkuInfo = '/admin/product/getSkuById',
}
// 保存 sku
export const reqSaveSkuInfo = (skuInfo: skuInfoModel) => service.post(API.saveSkuInfo, skuInfo)

// 获取 skuList
export const reqGetSkuList = (page: number, limit: number) => service.get<any, skuListResponse>(`${API.getSkuList}/${page}/${limit}`)

// 上架
export const reqOnSale = (skuId: number) => service.get(`${API.onSale}/${skuId}`)

// 下架
export const reqCancelSale = (skuId: number) => service.get(`${API.cancelSale}/${skuId}`)

// 删除
export const reqDeleteSkuInfo = (skuId: number) => service.delete(`${API.deleteSkuInfo}/${skuId}`)

// 获取 spu 中的 sku
export const reqGetSkuListBySpuId = (spuId: number) => service.get<any, skuInfoModel[]>(`${API.getSkuListBySpuId}/${spuId}`)

// 获取 sku 的详细信息
export const reqGetSkuInfo = (skuId: number) => service.get<any, skuInfoModel>(`${API.getSkuInfo}/${skuId}`)